package com.yukefms.engine;

import com.yukefms.common.BoundedQueue;
import com.yukefms.engine.EngineConfig;
import com.yukefms.engine.interfaces.PositionCacheStructure;
import com.yukefms.jointpoint.BodyPointCloud;

/**
 * @Description A structure for caching last certain number of read positions as given.
 * @Author Ping
 * @Date 2021/6/30 14:11
 **/
public class DefaultPositionCacheStructure implements PositionCacheStructure {

    private BoundedQueue<BodyPointCloud> cacheQueue ;
    private BodyPointCloud startBodyPoint ;



    public DefaultPositionCacheStructure() {
        this.cacheQueue = new BoundedQueue<BodyPointCloud>(EngineConfig.LAST_NUM) ;
    }

    @Override
    public BodyPointCloud getLast() {
        return this.cacheQueue.first();
    }

    @Override
    public BodyPointCloud getLast(String bId) {
        return this.cacheQueue.first();
    }

    @Override
    public BodyPointCloud getStart() {
        return this.startBodyPoint;
    }

    @Override
    public void update(BodyPointCloud pointCloud) {
        this.cacheQueue.add(pointCloud) ;
    }

    @Override
    public void cacheStart(BodyPointCloud pointCloud) {
        this.cacheQueue.resetByVal(pointCloud);
        this.startBodyPoint = pointCloud ;
    }

    @Override
    public boolean hasLast() {
        return  this.cacheQueue.empty() == false ;
    }

    @Override
    public void reset() {
        this.cacheQueue.reset() ;
    }
}
